home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F17660_dates2.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-09-23  |  2.5 KB  |  55 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- ============================================================
  3. Example for sorting dates in the format m/d/yy
  4. Use with: Dates2.xml
  5. Notes:-
  6. 1) The day and month portion of the date can be one or two digits
  7.    therefore it is necessary to pad these with zeroes so that
  8.    final sort select is a constant length numeric.
  9. ================================================================= -->
  10. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  11. <xsl:output method="html" encoding="ISO-8859-1" indent="yes"/>
  12. <!-- define variable that is used as the separator in dates -->
  13. <!-- (this saves having to re-work the code for different separators -->
  14. <xsl:variable name="date-sep" select="'/'"/>
  15. <xsl:template match="/">
  16.     <html><body>
  17.     <table border="1">
  18.         <tr>
  19.             <th>Sorted Position</th>
  20.             <th>Sort value</th>
  21.             <th>Original date value</th>
  22.             <th>Original position</th>
  23.         </tr>
  24.         <xsl:for-each select="/root/item">
  25.             <!-- sort algorithm -->
  26.             <xsl:sort select="concat(
  27.                 substring('00',1,2-string-length(substring-after(substring-after(@date,$date-sep),$date-sep))),substring-after(substring-after(@date,$date-sep),$date-sep),
  28.                 concat(substring('00',1,2-string-length(substring-before(@date,$date-sep))),substring-before(@date,$date-sep)),
  29.                 concat(substring('00',1,2-string-length(substring-before(substring-after(@date,$date-sep),$date-sep))),substring-before(substring-after(@date,$date-sep),$date-sep))
  30.                 )" data-type="number"/>
  31.             <tr>
  32.                 <td>
  33.                     <xsl:value-of select="position()"/>
  34.                 </td>
  35.                 <td>
  36.                     <!-- the year portion -->
  37.                     <xsl:value-of select="concat(substring('00',1,2-string-length(substring-after(substring-after(@date,$date-sep),$date-sep))),substring-after(substring-after(@date,$date-sep),$date-sep))"/>
  38.                     <!-- the month portion -->
  39.                     <xsl:value-of select="concat(substring('00',1,2-string-length(substring-before(@date,$date-sep))),substring-before(@date,$date-sep))"/>
  40.                     <!-- the day portion -->
  41.                     <xsl:value-of select="concat(substring('00',1,2-string-length(substring-before(substring-after(@date,$date-sep),$date-sep))),substring-before(substring-after(@date,$date-sep),$date-sep))"/>
  42.                 </td>
  43.                 <td>
  44.                     <xsl:value-of select="@date"/>
  45.                 </td>
  46.                 <td>
  47.                     <!-- show the order of the element in the original xml -->
  48.                     <xsl:value-of select="count(preceding-sibling::item)+1"/>
  49.                 </td>
  50.             </tr>
  51.         </xsl:for-each>
  52.     </table>
  53.     </body></html>
  54. </xsl:template>
  55. </xsl:stylesheet>